package AAAAAAA;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class BIOTest {

    public static void writeByBIO(String path, String context) {
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(path, true);

            for (int i = 0 ; i < 3 ; i++) {
                fos.write((context + "\n").getBytes());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void readByBIO(String path) {
        FileInputStream fis = null;

        try {
            fis = new FileInputStream(path);
            int length;

            while ((length = fis.read()) != -1) {
//                System.out.print((char) length);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                writeByBIO("F:\\Hello.log", "1");
            }
        }).start();

        new Thread(new Runnable() {

            @Override
            public void run() {
                writeByBIO("F:\\Hello.log", "2");
            }
        }).start();

        new Thread(new Runnable() {

            @Override
            public void run() {
                readByBIO("F:\\Hello.log");
            }
        }).start();
    }


}
